from bottle import route, template, request, response
from app.middlewares.route import app_route

@app_route('/')
def index():
    return template('home')

@app_route('/login', method=['GET', 'POST'])
def login():
    if request.method == 'POST':
        # 假设这里验证用户名密码
        username = request.forms.get('username')
        password = request.forms.get('password')
        if username == 'admin' and password == 'password':  # 示例，实际应使用安全方式验证
            session = request.environ.get('beaker.session')
            session['logged_in'] = True
            session.save()
            return redirect('/')
        else:
            return "<p>登录失败</p>"
    return '''
        <h1>请登录</h1>
        <form action="/login" method="post">
            Username: <input name="username" type="text"/>
            Password: <input name="password" type="password"/>
            <input value="Login" type="submit"/>
        </form>
    '''